<?php

namespace App\Model;


class MallGoodsSku extends BaseModel
{
    protected $table = 'mall_goods_sku';
    protected $primaryKey = 'sku_id';
    public $timestamps = false;
    protected $fillable = ['goods_id','time_limit','price','create_timestamp'];
    CONST STATUS_DEFAULT = 1;
    CONST STATUS_NOT_DEFAULT = 0;
    public function mallGoods(){
        return $this->belongsTo(MallGoods::class, 'goods_id', 'goods_id');
    }
    
    public function scopeOfDefault($query){
        return $query->where('default',self::STATUS_DEFAULT);
    }
    
    public function getDefaultMallGoodsSkuByGoodsId(int $goods_id){
        return MallGoodsSku::ofDefault()->where('goods_id',$goods_id)->first();
    }
    
    public function getSkuByGoodsId($goods_id){
        return self::where('goods_id', $goods_id)->get();
    }
    
    public function getSkuBySkuId($sku_id){
        return self::where('sku_id', $sku_id)->first();
    }
}
